package zzg.study.codec;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import zzg.study.protocol.PacketCodec;

import java.util.List;

/**
 * @Classname PacketDecoder
 * @Description netty提供特殊的handle实现解码
 * @Date 2023/12/3 18:35
 * @Author zhuzhenguo
 */
public class PacketDecoder extends MessageToMessageDecoder<ByteBuf> {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
        // 在out中添加解码后的结果对象，就可以自动实现结果向下一个handle传递
        out.add(PacketCodec.INSTANCE.decode(in));
    }

}
